package org.jogdiary2011.controller.exerciseResult;

import org.jogdiary2011.model.ExerciseResult;
import org.jogdiary2011.service.ExerciseResultService;
import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.controller.validator.Validators;
import org.slim3.util.RequestMap;

public class InsertController extends Controller {

    private ExerciseResultService exerciseResultService = new ExerciseResultService();
    
    @Override
    public Navigation run() throws Exception {
        if (!validate()) {
            return forward("create.jsp");
        }
        ExerciseResult exerciseResult = exerciseResultService.insert(new RequestMap(request));
        return redirect("/");
    }
    
    private boolean validate() {
        Validators v = new Validators(request);
        v.add("exerciseDate", v.required());
        return v.validate();
    }
}
